function renderIndex() {
    $(".carousel-inner").html("");
    $.each(activitys, function(index, activity) {
        var classname = (index <= 0) ? "active" : "";
        $(".carousel-inner").append('<div class="carousel-item '+classname+'"><img src="'+activity.image+'"></div>');
        $(".carousel-indicators").append('<li data-target="#demo" data-slide-to="'+index+'" class="'+classname+'"></li>');
    });
}

function jsUploadCallBack(url) {
    showQrcodes();
}

function showQrcodes() {
    var msg_qrcodes = $("#msg_qrcodes").val();
    if (msg_qrcodes == "") {
        $(".file-border-delete").show();
    }
    var msg_qrcode = msg_qrcodes.split(",");
    var new_msg_qrcode = "";
    $(".mini-edit-images").html("");
    $("#msg_qrcodes_lists").html("");
    $.each(msg_qrcode,function(idx,qrcode){
        if (qrcode != "") {
            var imageid = Math.ceil(Math.random()*10000000);
            $("#msg_qrcodes_lists").prepend('<div id="'+imageid+'"><img src="'+qrcode+'" class="file-border-view-lists"><i class="file-cotainer-icon iconfont icon-guanbi" onclick=\'deleteImages("msg_qrcodes","'+qrcode+'","'+imageid+'");\'></i></div>');
            $(".mini-edit-images").append('<img src="'+qrcode+'" />');
        }
    });
    $(".file-border-delete").show();
}

function submitStyle(appid) {
    var msg_qrcodes = $("#msg_qrcodes").val();
    if(msg_qrcodes == ""){
        toastError("小程序更新失败","请上传小程序首页图片!");
        return;
    }
    $.ajax({
        "url": "/admin/miniapp_set/index_setting",
        "type": "POST",
        headers: {
            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
        },
        data: {
            "appid": appid,
            "images": msg_qrcodes,
        },
        success: function(res){
            if (res.status == "success") {
                toastSuccess("小程序更新成功",res.msg);
                setTimeout(function(){
                    location.reload();
                },2000);
            } else {
                toastError("小程序更新失败",res.msg);
            }
        },
        fail: function() {
            toastError("请求失败","请稍后重试！!");
        }
    });
}

function deleteImages(id,image,imageid) {
    $("#"+imageid).remove();
    var msg_qrcodes = $("#msg_qrcodes").val();
    var images = msg_qrcodes.split(",");
    var new_images = "";
    $.each(images,function(idx,fimage){
        if (fimage != image) {
            if (idx != 0) {
                new_images += ","
            }
            new_images += fimage;
        }
    });
    $("#msg_qrcodes").val(new_images);
    showQrcodes();
}
